from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-15 14:29:33.283720
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 15, Jan, 2021
Time: 14:29:37
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.1338
Nobs: 172.000 HQIC: -46.1126
Log likelihood: 1916.63 FPE: 4.82930e-21
AIC: -46.7808 Det(Omega_mle): 2.90401e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.447612 0.149348 2.997 0.003
L1.Burgenland 0.136817 0.077301 1.770 0.077
L1.Kärnten -0.234870 0.062720 -3.745 0.000
L1.Niederösterreich 0.136770 0.179185 0.763 0.445
L1.Oberösterreich 0.230453 0.153424 1.502 0.133
L1.Salzburg 0.181937 0.081238 2.240 0.025
L1.Steiermark 0.079907 0.111046 0.720 0.472
L1.Tirol 0.156944 0.073575 2.133 0.033
L1.Vorarlberg 0.016370 0.070102 0.234 0.815
L1.Wien -0.137342 0.149124 -0.921 0.357
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.526037 0.190766 2.758 0.006
L1.Burgenland 0.012960 0.098738 0.131 0.896
L1.Kärnten 0.371310 0.080114 4.635 0.000
L1.Niederösterreich 0.134480 0.228877 0.588 0.557
L1.Oberösterreich -0.177301 0.195971 -0.905 0.366
L1.Salzburg 0.174702 0.103767 1.684 0.092
L1.Steiermark 0.237973 0.141841 1.678 0.093
L1.Tirol 0.145569 0.093979 1.549 0.121
L1.Vorarlberg 0.190548 0.089542 2.128 0.033
L1.Wien -0.601507 0.190479 -3.158 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.303873 0.065744 4.622 0.000
L1.Burgenland 0.105994 0.034029 3.115 0.002
L1.Kärnten -0.024780 0.027610 -0.898 0.369
L1.Niederösterreich 0.060486 0.078879 0.767 0.443
L1.Oberösterreich 0.284969 0.067538 4.219 0.000
L1.Salzburg 0.000100 0.035762 0.003 0.998
L1.Steiermark -0.022403 0.048883 -0.458 0.647
L1.Tirol 0.096444 0.032388 2.978 0.003
L1.Vorarlberg 0.125578 0.030859 4.069 0.000
L1.Wien 0.076118 0.065646 1.160 0.246
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.216712 0.077601 2.793 0.005
L1.Burgenland -0.008604 0.040165 -0.214 0.830
L1.Kärnten 0.023526 0.032589 0.722 0.470
L1.Niederösterreich 0.032382 0.093104 0.348 0.728
L1.Oberösterreich 0.388601 0.079718 4.875 0.000
L1.Salzburg 0.090980 0.042211 2.155 0.031
L1.Steiermark 0.181646 0.057699 3.148 0.002
L1.Tirol 0.044382 0.038229 1.161 0.246
L1.Vorarlberg 0.100415 0.036424 2.757 0.006
L1.Wien -0.071767 0.077484 -0.926 0.354
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.565320 0.155042 3.646 0.000
L1.Burgenland 0.077680 0.080248 0.968 0.333
L1.Kärnten 0.005774 0.065111 0.089 0.929
L1.Niederösterreich -0.013249 0.186016 -0.071 0.943
L1.Oberösterreich 0.131549 0.159273 0.826 0.409
L1.Salzburg 0.044378 0.084335 0.526 0.599
L1.Steiermark 0.110931 0.115279 0.962 0.336
L1.Tirol 0.225675 0.076380 2.955 0.003
L1.Vorarlberg 0.018655 0.072774 0.256 0.798
L1.Wien -0.151867 0.154809 -0.981 0.327
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162560 0.109649 1.483 0.138
L1.Burgenland -0.022681 0.056753 -0.400 0.689
L1.Kärnten -0.011351 0.046048 -0.247 0.805
L1.Niederösterreich 0.182328 0.131555 1.386 0.166
L1.Oberösterreich 0.379633 0.112641 3.370 0.001
L1.Salzburg -0.034535 0.059644 -0.579 0.563
L1.Steiermark -0.048728 0.081528 -0.598 0.550
L1.Tirol 0.196481 0.054017 3.637 0.000
L1.Vorarlberg 0.049521 0.051467 0.962 0.336
L1.Wien 0.154208 0.109484 1.408 0.159
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.224956 0.138331 1.626 0.104
L1.Burgenland 0.065174 0.071598 0.910 0.363
L1.Kärnten -0.049448 0.058093 -0.851 0.395
L1.Niederösterreich -0.031741 0.165967 -0.191 0.848
L1.Oberösterreich -0.091926 0.142105 -0.647 0.518
L1.Salzburg 0.026320 0.075245 0.350 0.726
L1.Steiermark 0.370654 0.102854 3.604 0.000
L1.Tirol 0.511926 0.068147 7.512 0.000
L1.Vorarlberg 0.194086 0.064930 2.989 0.003
L1.Wien -0.217885 0.138123 -1.577 0.115
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.077146 0.163338 0.472 0.637
L1.Burgenland 0.018167 0.084542 0.215 0.830
L1.Kärnten -0.100113 0.068595 -1.459 0.144
L1.Niederösterreich 0.250474 0.195969 1.278 0.201
L1.Oberösterreich 0.013897 0.167795 0.083 0.934
L1.Salzburg 0.220724 0.088848 2.484 0.013
L1.Steiermark 0.143747 0.121447 1.184 0.237
L1.Tirol 0.097389 0.080466 1.210 0.226
L1.Vorarlberg 0.027207 0.076668 0.355 0.723
L1.Wien 0.257621 0.163092 1.580 0.114
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.598610 0.088063 6.798 0.000
L1.Burgenland -0.023083 0.045580 -0.506 0.613
L1.Kärnten -0.002240 0.036983 -0.061 0.952
L1.Niederösterreich -0.017280 0.105656 -0.164 0.870
L1.Oberösterreich 0.275664 0.090466 3.047 0.002
L1.Salzburg 0.008610 0.047902 0.180 0.857
L1.Steiermark 0.001223 0.065478 0.019 0.985
L1.Tirol 0.078934 0.043383 1.819 0.069
L1.Vorarlberg 0.168430 0.041335 4.075 0.000
L1.Wien -0.083182 0.087931 -0.946 0.344
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.151846 -0.000699 0.216871 0.255228 0.069427 0.091105 -0.059024 0.157714
Kärnten 0.151846 1.000000 -0.000251 0.190956 0.156277 -0.129550 0.161202 0.032037 0.302891
Niederösterreich -0.000699 -0.000251 1.000000 0.281193 0.083184 0.213553 0.097554 0.059394 0.352460
Oberösterreich 0.216871 0.190956 0.281193 1.000000 0.294856 0.311544 0.080778 0.080891 0.119800
Salzburg 0.255228 0.156277 0.083184 0.294856 1.000000 0.156433 0.070034 0.083432 -0.024118
Steiermark 0.069427 -0.129550 0.213553 0.311544 0.156433 1.000000 0.099305 0.095336 -0.121812
Tirol 0.091105 0.161202 0.097554 0.080778 0.070034 0.099305 1.000000 0.150453 0.130437
Vorarlberg -0.059024 0.032037 0.059394 0.080891 0.083432 0.095336 0.150453 1.000000 0.094951
Wien 0.157714 0.302891 0.352460 0.119800 -0.024118 -0.121812 0.130437 0.094951 1.000000